package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.HotNewsMapper;
import com.yuwubao.uav.tool.service.HotNewsService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class HotNewsServiceImpl implements HotNewsService {

    private static final Logger logger = LogManager.getLogger(HotNewsServiceImpl.class.getName());

    @Resource
    private HotNewsMapper hotNewsMapper;

    @Override
    public void deleteHotNews(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    hotNewsMapper.deleteHotNews(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateHotNews(PageData pageData) throws Exception {
        try{
            hotNewsMapper.updateHotNews(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableHotNews(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    hotNewsMapper.disableOrEnableHotNews(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableHotNewsType(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    hotNewsMapper.disableOrEnableHotNewsType(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addHotNews(PageData pageData) throws Exception {
        try{
            hotNewsMapper.addHotNews(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listHotNews(PageData pageData) throws Exception {
        try{
            return hotNewsMapper.listHotNews(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listHotNewsCount(PageData pageData) throws Exception {
        try{
            return hotNewsMapper.listHotNewsCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    @Override
    public void deleteHotNewsType(PageData pageData) throws Exception {
        try{

            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");

            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    hotNewsMapper.deleteHotNewsType(pageData);

                }
            }


        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateHotNewsType(PageData pageData) throws Exception {
        try{
            hotNewsMapper.updateHotNewsType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public void addHotNewsType(PageData pageData) throws Exception {
        try{
            String names = pageData.get("names") == null ? "" : pageData.getString("names");
            if (StringUtil.isNotNvlOrBlank(names)) {
                String[] nameArr = names.split(",");
                if (nameArr != null && nameArr.length>0) {
                    for (String name : nameArr) {
                        pageData.put("name",name);
                        hotNewsMapper.addHotNewsType(pageData);
                    }
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listHotNewsType(PageData pageData) throws Exception {
        try{
            return hotNewsMapper.listHotNewsType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public List<PageData> listHotNewsTypeAll(PageData pageData) throws Exception {
        try{
            return hotNewsMapper.listHotNewsTypeAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listHotNewsTypeCount(PageData pageData) throws Exception {
        try{
            return hotNewsMapper.listHotNewsTypeCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

}
